package org.micode.demo.db.domain.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.micode.common.helper.I18nMsgHelper;
import org.micode.common.validater.InsertGroup;
import org.micode.common.validater.UpdateGroup;
import org.micode.common.validater.EnumValidation;
import org.micode.common.exception.VerifyFailException;
import org.micode.common.utils.StringExtUtils;
import org.micode.common.domain.base.entity.BaseNormalEntity;

import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.PositiveOrZero;
import javax.validation.constraints.Size;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * 用户所属角色实体类
 *
 * @author: wutianbin
 * @version: v1.0.27
 * @CreateDate: 2021-11-10
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class SysUserRoleDO extends BaseNormalEntity<Long> {

    /** ID，Long */
    @NotNull(message = "{entity.valid.SysUserRoleDO.id.NotNull}", groups = UpdateGroup.class)
    @PositiveOrZero(message = "{entity.valid.SysUserRoleDO.id.PositiveOrZero}", groups = {UpdateGroup.class})
    private Long id;

    /** 用户ID，Long */
    @NotNull(message = "{entity.valid.SysUserRoleDO.userId.NotNull}", groups = InsertGroup.class)
    @PositiveOrZero(message = "{entity.valid.SysUserRoleDO.userId.PositiveOrZero}", groups = {InsertGroup.class, UpdateGroup.class})
    private Long userId;

    /** 角色ID，Long */
    @NotNull(message = "{entity.valid.SysUserRoleDO.roleId.NotNull}", groups = InsertGroup.class)
    @PositiveOrZero(message = "{entity.valid.SysUserRoleDO.roleId.PositiveOrZero}", groups = {InsertGroup.class, UpdateGroup.class})
    private Long roleId;

    @JsonIgnore
    @Override
    public Long getKeyValue() {
        return id;
    }

    @Override
    public void checkBeforeInsert() {
        if (null == userId) {
            throw new VerifyFailException(I18nMsgHelper.get("entity.valid.SysUserRoleDO.userId.NotNull"));
        }
        if (null == roleId) {
            throw new VerifyFailException(I18nMsgHelper.get("entity.valid.SysUserRoleDO.roleId.NotNull"));
        }
    }

    @Override
    public String toString() {
        return "id=" + id +
                ", userId=" + userId +
                ", roleId=" + roleId +
                ", " + super.toString();
    }

}
